#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    private:
    int num;

    public:
    //sort
    int ans1(vector<int>& nums){
        // sort(nums.begin(), nums.end());
        // int ret = nums[0];
        int ret = *min_element(nums.begin(), nums.end());
        return ret;
    }

    //二分法+递归
    int ans2(vector<int>& nums){
        num = INT32_MAX;
        int len = nums.size();
        fun(nums, 0, len-1);

        return num;
    }

    void fun(vector<int>& nums, int left, int right){
        if(left > right){
            return;
        }
        int mid = left + (right - left) / 2;
        num = min(num, nums[mid]);
        fun(nums, left, mid-1);
        fun(nums, mid+1, right);
    }
};

void test1(){
    Solution s;
    vector<int> nums = {3,4,5,1,2};

    // int ret = s.ans1(nums);
    int ret = s.ans2(nums);
    cout << ret << endl;
}

void test2(){
    Solution s;
    vector<int> nums = {4,5,6,7,0,1,2};

    // int ret = s.ans1(nums);
    int ret = s.ans2(nums);
    cout << ret << endl;
}

void test3(){
    Solution s;
    vector<int> nums = {11,13,15,17};

    // int ret = s.ans1(nums);
    int ret = s.ans2(nums);
    cout << ret << endl;
}

int main(void){
    test1();
    test2();
    test3();

    return 0;
}